<?php
/**
 * Created by PhpStorm.
 * User: jieaido
 * Date: 2017/4/1
 * Time: 16:04
 */
namespace Home\Controller;
use Think\Controller;
class StationController extends MyController{
    public function addstation()
    {
        $this->display();
    }


//    public function addstation_post()
//    {
//
//        $data=array('name'=>I('stationname'));
//        M('station')->add($data);
//        $this->success('添加成功');
//    }

    public function stationlist()
    {
       $result= M('station')->select();
        $this->ajaxReturn($result);
    }

    public function station_delete()
    {
        $this->Checklogin();
        if (IS_AJAX) {
         $result= M('station')->delete(I('id'));
            if ($result) {
                return $this->ajaxReturn(array('msg'=>'删除成功','status'=>1));
            }
            return $this->ajaxReturn(array('msg'=>'删除失败','status'=>0));
        }

    }

    public function station_post()
    {
        $this->Checklogin();
        if (IS_AJAX){
            $station=M('station');
                $id=I('id');
            if (!empty($id)){//有ID传入说明是修改
            $station->id=$id;
            $station->name=I('name');
                M('station')->save();
                return $this->ajaxReturn(array('msg'=>'修改成功','status'=>1));
            }else{//没有ID就是新建
               $station->name=I('name');
               $station->add();
                return $this->ajaxReturn(array('msg'=>'添加成功','status'=>1));
            }


        }
    }
}